//
//  Loan_SignedAgreementViewController.m
//  JinFuThree
//
//  Created by 爱尚 on 2018/9/19.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "Loan_SignedAgreementViewController.h"
#import "Loan_OrderAffirmViewController.h"

@interface Loan_SignedAgreementViewController ()

@property(nonatomic,strong)UIButton *agreeBtn;

@end

@implementation Loan_SignedAgreementViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"电子合同签约";
    [self initViews];
    
}

-(void)commitBtnAction{
    if (self.agreeBtn.selected == NO) {
        [HUD_Mao showCharacterMessage:@"需同意相关协议才能进行提交"];
        return;
    }
    
    Loan_OrderAffirmViewController *affirmVC = [[Loan_OrderAffirmViewController alloc]init];
    [self.navigationController pushViewController:affirmVC animated:YES];
}

-(void)initViews{
    UIView *progressView = [[UIView alloc]init];
    progressView.backgroundColor = ThemeMaoColor;
    [self.view addSubview:progressView];
    [progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(self.view);
        make.width.mas_offset(@(ScreenWidthMao/6*6));
        make.height.mas_offset(@2);
    }];
    
    UIImageView *centerImageView = [[UIImageView alloc]init];
    centerImageView.image = [UIImage imageNamed:@"loan_ic_xieyi"];
    [self.view addSubview:centerImageView];
    [centerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.centerY.mas_equalTo(self.view.mas_centerY).offset(-50);
        make.height.mas_offset(@(ScreenWidthMao/375*232));
        make.width.mas_offset(@(ScreenWidthMao/375*274));
    }];
    
    UIButton *commitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [commitBtn setTitle:@"提交" forState:UIControlStateNormal];
    [commitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    commitBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [commitBtn setBackgroundColor:ThemeMaoColor];
    commitBtn.layer.masksToBounds = YES;
    commitBtn.layer.cornerRadius = 4;
    [commitBtn setBackgroundImage:[UIImage imageNamed:@"select_btn"] forState:UIControlStateNormal];
    [commitBtn addTarget:self action:@selector(commitBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:commitBtn];
    [commitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).offset(25);
        make.right.mas_equalTo(self.view.mas_right).offset(-25);
        make.bottom.mas_equalTo(self.view.mas_bottom).offset(-30);
        make.height.mas_offset(@44);
    }];
    
    _agreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_agreeBtn setTitle:@"本人已阅读并同意" forState:UIControlStateNormal];
    [_agreeBtn setTitleColor:ThemeMaoBlackColor forState:UIControlStateNormal];
    _agreeBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [_agreeBtn setImage:[UIImage imageNamed:@"loan_btn_wgx"] forState:UIControlStateNormal];
    [_agreeBtn setImage:[UIImage imageNamed:@"loan_btn_gx"] forState:UIControlStateSelected];
    _agreeBtn.selected = YES;
    [_agreeBtn addTarget:self action:@selector(agreeBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_agreeBtn];
    [self.agreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(commitBtn.mas_left);
        make.bottom.mas_equalTo(commitBtn.mas_top).offset(-45);
        make.width.mas_offset(@135);
        make.height.mas_offset(@30);
    }];
    
    UIButton *xieyiBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [xieyiBtn1 setTitle:@"《小雨点合同协议》、" forState:UIControlStateNormal];
    [xieyiBtn1 setTitleColor:ThemeMaoColor forState:UIControlStateNormal];
    xieyiBtn1.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.view addSubview:xieyiBtn1];
    [xieyiBtn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.agreeBtn.mas_right);
        make.height.centerY.mas_equalTo(self.agreeBtn);
        make.width.mas_offset(@135);
    }];
    
    UIButton *xieyiBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [xieyiBtn2 setTitle:@"《恒丰合同协议》、" forState:UIControlStateNormal];
    [xieyiBtn2 setTitleColor:ThemeMaoColor forState:UIControlStateNormal];
    xieyiBtn2.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.view addSubview:xieyiBtn2];
    
    UIButton *xieyiBtn3 = [UIButton buttonWithType:UIButtonTypeCustom];
    [xieyiBtn3 setTitle:@"《爱尚合同协议》" forState:UIControlStateNormal];
    [xieyiBtn3 setTitleColor:ThemeMaoColor forState:UIControlStateNormal];
    xieyiBtn3.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.view addSubview:xieyiBtn3];
    
    
    if (ScreenWidthMao>375) {
        [xieyiBtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(xieyiBtn1.mas_right).offset(-10);
            make.height.mas_equalTo(self.agreeBtn);
            make.width.mas_offset(@130);
            make.centerY.mas_equalTo(xieyiBtn1).offset(0);
        }];
        
        [xieyiBtn3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.agreeBtn.mas_left).offset(0);
            make.height.mas_equalTo(xieyiBtn2);
            make.width.mas_offset(@130);
            make.top.mas_equalTo(self.agreeBtn.mas_bottom).offset(-10);
        }];
    }else{
        [xieyiBtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.agreeBtn.mas_left).offset(24);
            make.height.mas_equalTo(self.agreeBtn);
            make.width.mas_offset(@130);
            make.top.mas_equalTo(self.agreeBtn.mas_bottom).offset(-10);
        }];
        
        [xieyiBtn3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(xieyiBtn2.mas_right).offset(-10);
            make.centerY.height.mas_equalTo(xieyiBtn2);
            make.width.mas_offset(@130);
        }];
    }
    
    
    
}
-(void)agreeBtnAction:(UIButton *)sender{
    sender.selected = !sender.selected;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
